<template>
  <el-container>
    <!-- 左侧菜单 -->
    <el-aside width="200px" v-show="isCollapse">
      <div
        style="
          background-color: transparent;
          line-height: 35px;
          padding-top: 10px;
        "
      >
        <img
          src="../../assets/images/yxlm.png"
          alt=""
          style="width: 200px; height: 100px"
        />
      </div>
      <el-row class="tac">
        <el-col :span="24">
          <el-menu
            :default-active="default_active"
            class="el-menu-vertical-demo"
            background-color="transparent"
            @open="handleOpen"
            @close="handleClose"
            router
            active-text-color="#409EFF"
          >
            <el-menu-item index="/admin/dashboard">
              <i class="el-icon-table-lamp" style="font-size:24px"></i>
              <span slot="title" style="font-size:20px;">首&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;页 </span>
            </el-menu-item>
            <el-menu-item index="/admin/user">
              <i class="el-icon-female" style="font-size:24px"></i>
              <span slot="title" style="font-size:20px;">召 唤 师</span>
            </el-menu-item>
            <el-menu-item index="/admin/goods">
              <i class="el-icon-trophy-1"  style="font-size:24px"></i>
              <span slot="title" style="font-size:20px;">英雄管理</span>
            </el-menu-item>
          </el-menu>
        </el-col>
      </el-row>
    </el-aside>
    <!-- 右侧 -->
    <el-container>
      <!-- 头部 -->
      <el-header>
        <i
          class="el-icon-s-fold spani"
          style="font-size: 24px; cursor: pointer;margin-top:15px"
          @click="isCollapse = !isCollapse"
        >
        </i>
        <i>
          欢迎<span class="sp1">【<span class="sp2">{{ uname }}</span>】</span>君临!
        </i>
        <i>
          <el-button style="color:white;background:transparent" @click="logout">退出</el-button>
        </i>
      </el-header>
      <!-- 页面功能 -->
      <el-main><router-view></router-view></el-main>
      <!-- 底部 -->
      <el-footer>HTML2204</el-footer>
    </el-container>
  </el-container>
</template>

<script>
import {tip} from '@/tools/function'
import req from '@/http/req'
export default {
  data() {
    return {
      uname: localStorage.getItem("username"),
      default_active: this.$route.fullPath,
      isCollapse: true,
    };
  },
  //组件生命周期   组件创建前
  // beforeCreate(){
  //   if(!localStorage.getItem('token')){
  //     this.$tip('请先登录','error')
  //     this.$router.replace('/login')
  //   } else {
  //     this.$http.get('http://10.70.30.40:5000/api/v1/profile').then((res) => {
  //       if (res.data.code === 401) {
  //         this.$tip('请先登录','error')
  //         this.$router.replace('/login')
  //       }else{
  //         localStorage.setItem('userInfo',JSON.stringify(res.data.data))
  //       }
  //     })
  //   }
  // },

  //组件内路由前置守卫
  // beforeRouteEnter(to,from,next){
  //   if(!localStorage.getItem('token')){
  //     tip('请先登录','error')
  //     next('/login')
  //   } else {
  //     req.get('http://10.70.30.40:5000/api/v1/profile').then((res) => {
  //       if (res.data.code === 401) {
  //         tip('请先登录','error')
  //         next('/login')
  //       }else{
  //         localStorage.setItem('userInfo',JSON.stringify(res.data.data))
  //       }
  //     })
  //   }
  // },
  methods: {
    logout(){
      this.$tip('注销成功','warning')
      localStorage.removeItem('token')
      this.$router.replace('/login')
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<style lang="scss" scoped>
.el-container {
  height: 100vh;
   background: #ff8235; /* fallback for old browsers */
  background: -webkit-linear-gradient(
    to right,
    #30e8bf,
    #ff8235
  ); /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(
    to right,
    #30e8bf,
    #ff8235
  ); 
}
.el-aside {
   /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  color: #333;
  text-align: center;
  line-height: 200px;
}
.el-footer {
  background-color: transparent;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-header {
  background-color: transparent;
  color: #333;
  text-align: left;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  .sp1 {
    font-size: 30px;
    color: #f7093c;
    font-weight: bold;
    .sp2{
      color: gold;
      font-size: 40px;
    }
  }
}
.el-main {
  background: transparent;
  margin: 15px 15px;
  color: #333;
  text-align: center;
  // line-height: 160px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.el-menu {
  border: 0;
}
.el-menu-item {
  text-align: left;
}
.is-active {
  color: #409eff;
}
.el-menu-item:hover {
  background-color: transparent !important;
}
</style>